package com.unicloud.medical.oss.common.model.request;

import com.unicloud.medical.oss.common.model.FileMetaData;
import com.unicloud.medical.oss.common.util.CommonUtil;
import com.unisound.tracelog.common.config.jackson.TraceLogJsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class InnerUploadObjectsRequest extends CommonRequest {

    /**
     * 桶名称
     */
    private String bucketName;

    /**
     * 文件夹
     */
    private String folder;

    /**
     * 文件列表
     */
    @TraceLogJsonIgnore
    private List<FileMetaData> files;


    public void setBucketName(String bucketName) {
        this.bucketName = StringUtils.trimToNull(bucketName);
    }

    public void setFolder(String folder) {
        this.folder = CommonUtil.formatFolder(folder);
    }

    @Override
    public String toString() {
        return "{"
                + "\"ossName\":\""
                + ossName + '\"'
                + ",\"files\":"
                + files.stream().map(file -> file.getFileName()).collect(Collectors.toList())
                + ",\"bucketName\":\""
                + bucketName + '\"'
                + ",\"folder\":\""
                + folder + '\"'
                + "}";
    }
}
